package ivan.cheng.activitys;


import ivan.cheng.Const;
import ivan.cheng.R;
import ivan.cheng.adapter.MainPermissionListAdapters;
import ivan.cheng.beans.permissionInfo;
import ivan.cheng.views.MyExpanableListView;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PermissionInfo;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.ExpandableListView.OnChildClickListener;

import com.umeng.analytics.MobclickAgent;

public class PermissionLevelActivity extends UIActivity {
    /** Called when the activity is first created. */
	private PackageManager mPackageManager = null;
	private BroadcastReceiver loadFinish = new LoadFinishReceiver();
	private MainPermissionListAdapters adapter;
	private ArrayList<ArrayList<permissionInfo>> mPermissionList;
	private ArrayList<String> parentLst;
	private MyExpanableListView mListView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MobclickAgent.onError(this);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.list_permission);
        mTitle = (TextView)findViewById(R.id.custom_title_txt);
		mTitle.setText(R.string.tab_title_level);
        this.getPackageManager();
        mPackageManager =  this.getPackageManager();
        //List<PackageInfo> packageLst = mPackageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
       // List<ApplicationInfo> appLst = mPackageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
        IntentFilter filter = new IntentFilter(Const.ACTION_LOADFINISH);
        this.registerReceiver(loadFinish, filter);
        mListView = (MyExpanableListView) this.findViewById(R.id.listbody);
        mListView.setOnChildClickListener(new OnChildClickListener() 
        {
			
			@Override
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				Intent intent = new Intent();
				intent.setClass(PermissionLevelActivity.this,
						PermissionDetailActivity.class);
				Bundle bundle = new Bundle();
				bundle.putStringArrayList(Const.EXTRA_PACKAGENAME_LIST,
						mPermissionList.get(groupPosition).get(childPosition).packageNameLst);
				bundle.putString(Const.EXTRA_PERMISSION_NAME, mPermissionList.get(groupPosition).get(childPosition).permissionName);
				intent.putExtras(bundle);
				startActivity(intent);
//				UMSnsService.share(PermissionManagerActivity.this,
//						"Android权限大揭密", new DataSendCallbackListener() 
//				{
//							@Override
//							public void onDataSendFinished(RETURN_STATUS arg0, SHARE_TO arg1) 
//							{
//								LogUtil.d("RETURN_STATUS:"+arg0);
//								LogUtil.d("SHARE_TO:"+arg1);
//							}
//							
//							@Override
//							public void onDataSendFailedWithException(UMSNSException arg0, SHARE_TO arg1) {
//								LogUtil.w("RETURN_STATUS:"+arg0);
//								LogUtil.w("SHARE_TO:"+arg1);
//							}
//						});
				return false;
			}
		});
        refresh();
        //(PackageManager)getSystemService(Context.)MainPermissionListAdapters
       // adapter = new ProcessListAdapter(this, (ArrayList<PackageInfo>)packageLst);
    }
    
    
    
    @Override
	protected void onResume() {
		super.onResume();
	}



	private MyExpanableListView getListView() 
    {
    	
        return mListView;
    }
    
    public void refresh() {
        setProgressBarIndeterminateVisibility(true);
		Thread t = new Thread(new Runnable() {

			@Override
			public void run() {
				getPermissionLst();
				Intent in = new Intent(Const.ACTION_LOADFINISH);
				PermissionLevelActivity.this.sendBroadcast(in);
			}

		});
		t.start();
    }
    
    protected void getPermissionLst() 
    {
    	InitPermission();
    	List<PackageInfo> packageLst = mPackageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    	Iterator<PackageInfo> it = packageLst.iterator();
    	while(it.hasNext())
    	{
    		PackageInfo pi = it.next();
    		if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0
					|| (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) > 0)
			{
				it.remove();
			}
//    		if(pi.applicationInfo.publicSourceDir.contains("/system/app/")||
//    				pi.applicationInfo.publicSourceDir.contains("/framework/system/"))
//    		{
//    			it.remove();
//    		}
    	}
    	for(PackageInfo pi:packageLst)
    	{
    		if(null != pi.requestedPermissions)
    		for(String perinfo:pi.requestedPermissions)
    		{
    			for(int i = 0; i < mPermissionList.size(); i++)
    				for(int k = 0; k < mPermissionList.get(i).size(); k++)
    			if(perinfo.equalsIgnoreCase(mPermissionList.get(i).get(k).permissionName))
    			{
    				mPermissionList.get(i).get(k).packageNameLst.add(pi.packageName);
    				break;
    			}
    		}
    	}
	}

    private void InitPermission()
    {
    	ArrayList<permissionInfo> temLst = new ArrayList<permissionInfo>();
    	//首先把所有权限都读取进来
    	temLst.add(new permissionInfo(R.drawable.ic_launcher_android,"开机自动运行","允许程序开机自动运行","android.permission.RECEIVE_BOOT_COMPLETED"));
    	temLst.add(new permissionInfo(R.drawable.e_mail,"发送短信","发送短信","android.permission.SEND_SMS"));
    	temLst.add(new permissionInfo(R.drawable.e_mail,"接收短信","接收短信","android.permission.RECEIVE_SMS"));
    	temLst.add(new permissionInfo(R.drawable.e_mail,"读取短信内容","读取短信内容","android.permission.READ_SMS"));
    	temLst.add(new permissionInfo(R.drawable.e_mail,"编写短信","允许编写短信","android.permission.WRITE_SMS"));
    	temLst.add(new permissionInfo(R.drawable.e_mail,"收到短信时广播","当收到短信时触发一个广播","android.permission.BROADCAST_SMS"));
    	temLst.add(new permissionInfo(R.drawable.e_mail,"接收彩信","允许程序接收彩信","android.permission.RECEIVE_MMS"));
    	temLst.add(new permissionInfo(R.drawable.e_mail,"接收Wap Push","接收WAP PUSH信息","android.permission.RECEIVE_WAP_PUSH"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"拨打电话","允许程序从非系统拨号器里输入电话号码","android.permission.CALL_PHONE"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"通话权限","允许程序拨打电话，替换系统的拨号器界面","android.permission.CALL_PRIVILEGED"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"修改电话状态","修改电话状态，如飞行模式，但不包含替换系统拨号器界面","android.permission.MODIFY_PHONE_STATE"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"读取电话状态","访问电话状态","android.permission.READ_PHONE_STATE"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"处理拨出电话","允许程序监视，修改或放弃播出电话","android.permission.PROCESS_OUTGOING_CALLS"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"读取联系人","允许应用访问联系人通讯录信息","android.permission.READ_CONTACTS"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"写入联系人","写入联系人，但不可读取","android.permission.WRITE_CONTACTS"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"获取粗略位置","通过WiFi或移动基站的方式获取用户错略的经纬度信息，定位精度大概误差在30~1500米","android.permission.ACCESS_COARSE_LOCATION"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"获取精确位置","通过GPS芯片接收卫星的定位信息，定位精度达10米以内","android.permission.ACCESS_FINE_LOCATION"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"访问定位额外命令","允许程序访问额外的定位提供者指令","android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"获取模拟定位信息","获取模拟定位信息，一般用于帮助开发者调试应用","android.permission.ACCESS_MOCK_LOCATION"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"改变配置","允许当前应用改变配置，如定位","android.permission.CHANGE_CONFIGURATION"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"控制定位更新","允许获得移动网络定位信息改变","android.permission.CONTROL_LOCATION_UPDATES"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"安装定位提供","安装定位提供","android.permission.INSTALL_LOCATION_PROVIDER"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"获取网络状态","获取网络信息状态，如当前的网络连接是否有效","android.permission.ACCESS_NETWORK_STATE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"改变网络状态","改变网络状态如是否能联网","android.permission.CHANGE_NETWORK_STATE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"改变WiFi多播状态","改变WiFi多播状态","android.permission.CHANGE_WIFI_MULTICAST_STATE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"获取WiFi状态","获取当前WiFi接入的状态以及WLAN热点的信息","android.permission.ACCESS_WIFI_STATE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"改变WiFi状态","改变WiFi状态","android.permission.CHANGE_WIFI_STATE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"访问网络","访问网络连接，可能产生GPRS流量","android.permission.INTERNET"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"写入GPRS接入点设置","写入网络GPRS接入点设置","android.permission.WRITE_APN_SETTINGS"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"访问账户Gmail列表","访问GMail账户列表","android.permission.GET_ACCOUNTS"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"写入日程提醒","写入日程，但不可读取","android.permission.WRITE_CALENDAR"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"读取日程提醒","允许程序读取用户的日程信息","android.permission.READ_CALENDAR"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"账户管理","获取账户验证信息，主要为GMail账户信息，只有系统级进程才能访问的权限","android.permission.ACCOUNT_MANAGER"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"验证账户","允许一个程序通过账户验证方式访问账户管理ACCOUNT_MANAGER相关信息","android.permission.AUTHENTICATE_ACCOUNTS"));
    	temLst.add(new permissionInfo(R.drawable.ic_launcher,"使用证书","允许程序请求验证从AccountManager","android.permission.USE_CREDENTIALS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"状态栏控制","允许程序打开、关闭、禁用状态栏","android.permission.STATUS_BAR"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置闹铃提醒","设置闹铃提醒","com.android.alarm.permission.SET_ALARM"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置总是退出","设置程序在后台是否总是退出","android.permission.SET_ALWAYS_FINISH"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置动画缩放","设置全局动画缩放","android.permission.SET_ANIMATION_SCALE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置调试程序","设置调试程序，一般用于开发","android.permission.SET_DEBUG_APP"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置屏幕方向","设置屏幕方向为横屏或标准方式显示，不用于普通应用","android.permission.SET_ORIENTATION"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置应用的参数","，设置应用的参数，已不再工作具体查看addPackageToPreferred(String) 介绍","android.permission.SET_PREFERRED_APPLICATIONS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置进程限制","允许程序设置最大的进程数量的限制","android.permission.SET_PROCESS_LIMIT"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置系统时间","设置系统时间","android.permission.SET_TIME"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置系统时区","设置系统时区","android.permission.SET_TIME_ZONE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置桌面壁纸","设置桌面壁纸","android.permission.SET_WALLPAPER"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置壁纸建议","设置壁纸建议","android.permission.SET_WALLPAPER_HINTS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"读写系统敏感设置","允许程序读写系统安全敏感的设置项","android.permission.WRITE_SECURE_SETTINGS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"读写系统设置","允许读写系统设置项","android.permission.WRITE_SETTINGS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"修改声音设置","修改声音设置信息","android.permission.MODIFY_AUDIO_SETTINGS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"使用振动","允许振动","android.permission.VIBRATE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"重启设备","允许程序重新启动设备","android.permission.REBOOT"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"排序系统任务","重新排序系统Z轴运行中的任务","android.permission.REORDER_TASKS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"结束系统任务","结束任务通过restartPackage(String)方法，该方式将在未来放弃","android.permission.RESTART_PACKAGES"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"拍照权限","允许访问摄像头进行拍照","android.permission.CAMERA"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"删除缓存文件","允许应用删除缓存文件","android.permission.DELETE_CACHE_FILES"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"删除应用","允许程序删除应用","android.permission.DELETE_PACKAGES"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"电源管理","允许访问底层电源管理","android.permission.DEVICE_POWER"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"结束后台进程","允许程序调用killBackgroundProcesses(String).方法结束后台进程","android.permission.KILL_BACKGROUND_PROCESSES"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"读取收藏夹和历史记录","读取浏览器收藏夹和历史记录","com.android.browser.permission.READ_HISTORY_BOOKMARKS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"写入收藏夹和历史记录","写入浏览器历史记录或收藏夹，但不可读取","com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"格式化文件系统","格式化可移动文件系统，比如格式化清空SD卡","android.permission.MOUNT_FORMAT_FILESYSTEMS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"挂 载文件系统","挂载、反挂载外部文件系统","android.permission.MOUNT_UNMOUNT_FILESYSTEMS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"写入外部存储","允许程序写入外部存储，如SD卡上写文件","android.permission.WRITE_EXTERNAL_STORAGE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"写入Google地图数据","允许程序写入Google Map服务数据","android.permission.WRITE_GSERVICES"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"写入在线同步设置","写入Google在线同步设置","android.permission.WRITE_SYNC_SETTINGS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"读取同步设置","读取同步设置，读取Google在线同步设置","android.permission.READ_SYNC_SETTINGS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"读取同步状态","读取同步状态，获得Google在线同步状态","android.permission.READ_SYNC_STATS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"屏幕截图","读取帧缓存用于屏幕截图","android.permission.READ_FRAME_BUFFER"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"访问登记属性","读取或写入登记check-in数据库属性表的权限","android.permission.ACCESS_CHECKIN_PROPERTIES"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"访问Surface Flinger","Android平台上底层的图形显示支持，一般用于游戏或照相机预览界面和底层模式的屏幕截图","android.permission.ACCESS_SURFACE_FLINGER"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"电量统计","获取电池电量统计信息","android.permission.BATTERY_STATS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"绑定小插件","允许一个程序告诉appWidget服务需要访问小插件的数据库，只有非常少的应用才用到此权限","android.permission.BIND_APPWIDGET"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"绑定设备管理","请求系统管理员接收者receiver，只有系统才能使用","android.permission.BIND_DEVICE_ADMIN"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"绑定输入法","请求InputMethodService服务，只有系统才能使用","android.permission.BIND_INPUT_METHOD"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"绑定RemoteView","必须通过RemoteViewsService服务来请求，只有系统才能用","android.permission.BIND_REMOTEVIEWS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"绑定壁纸","必须通过WallpaperService服务来请求，只有系统才能用","android.permission.BIND_WALLPAPER"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"使用蓝牙","允许程序连接配对过的蓝牙设备","android.permission.BLUETOOTH"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"蓝牙管理","允许程序进行发现和配对新的蓝牙设备","android.permission.BLUETOOTH_ADMIN"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"变成砖头","能够禁用手机，非常危险，顾名思义就是让手机变成砖头","android.permission.BRICK"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"应用删除时广播","当一个应用在删除时触发一个广播","android.permission.BROADCAST_PACKAGE_REMOVED"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"连续广播","允许一个程序收到广播后快速收到下一个广播","android.permission.BROADCAST_STICKY"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"WAP PUSH广播","WAP PUSH服务收到后触发一个广播","android.permission.BROADCAST_WAP_PUSH"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"设置Activity观察器","设置Activity观察器一般用于monkey测试","android.permission.SET_ACTIVITY_WATCHER"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"改变组件状态","改变组件是否启用状态","android.permission.CHANGE_COMPONENT_ENABLED_STATE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"清除应用缓存","清除应用缓存","android.permission.CLEAR_APP_CACHE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"清除用户数据","清除应用的用户数据","android.permission.CLEAR_APP_USER_DATA"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"底层访问权限","允许CWJ账户组访问底层信息","android.permission.CWJ_GROUP"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"手机优化大师扩展权限","手机优化大师扩展权限","android.permission.CELL_PHONE_MASTER_EX"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"应用诊断","允许程序到RW到诊断资源","android.permission.DIAGNOSTIC"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"禁用键盘锁","允许程序禁用键盘锁","android.permission.DISABLE_KEYGUARD"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"转存系统信息","允许程序获取系统dump信息从系统服务","android.permission.DUMP"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"状态栏控制","允许程序扩展或收缩状态栏","android.permission.EXPAND_STATUS_BAR"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"工厂测试模式","允许程序运行工厂测试模式","android.permission.FACTORY_TEST"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"使用闪光灯","允许访问闪光灯","android.permission.FLASHLIGHT"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"强制后退","允许程序强制使用back后退按键，无论Activity是否在顶层","android.permission.FORCE_BACK"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"获取应用大小","获取应用的文件大小","android.permission.GET_PACKAGE_SIZE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"获取任务信息","允许程序获取当前或最近运行的应用","android.permission.GET_TASKS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"允许全局搜索","允许程序使用全局搜索功能","android.permission.GLOBAL_SEARCH"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"硬件测试","访问硬件辅助设备，用于硬件测试","android.permission.HARDWARE_TEST"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"注射事件","允许访问本程序的底层事件，获取按键、轨迹球的事件流","android.permission.INJECT_EVENTS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"内部系统窗口","允许程序打开内部窗口，不对第三方应用程序开放此权限","android.permission.INTERNAL_SYSTEM_WINDOW"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"管理账户","允许程序管理AccountManager中的账户列表","android.permission.MANAGE_ACCOUNTS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"管理程序引用","管理创建、摧毁、Z轴顺序，仅用于系统","android.permission.MANAGE_APP_TOKENS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"高级权限","允许mTweak用户访问高级系统权限","android.permission.MTWEAK_USER"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"社区权限","允许使用mTweak社区权限","android.permission.MTWEAK_FORUM"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"软格式化","允许程序执行软格式化，删除系统配置信息","android.permission.MASTER_CLEAR"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"允许NFC通讯","允许程序执行NFC近距离通讯操作，用于移动支持","android.permission.NFC"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"永久Activity","创建一个永久的Activity，该功能标记为将来将被移除","android.permission.PERSISTENT_ACTIVITY"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"读取输入状态","读取当前键的输入状态，仅用于系统","android.permission.READ_INPUT_STATE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"读取系统日志","读取系统底层日志","android.permission.READ_LOGS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"录音","录制声音通过手机或耳机的麦克","android.permission.RECORD_AUDIO"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"发送永久进程信号","发送一个永久的进程信号","android.permission.SIGNAL_PERSISTENT_PROCESSES"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"访问订阅内容","访问订阅信息的数据库","android.permission.SUBSCRIBED_FEEDS_READ"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"写入订阅内容","写入或修改订阅内容的数据库","android.permission.SUBSCRIBED_FEEDS_WRITE"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"显示系统窗口","显示系统窗口","android.permission.SYSTEM_ALERT_WINDOW"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"更新设备状态","更新设备状态","android.permission.UPDATE_DEVICE_STATS"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"使用SIP视频","允许程序使用SIP视频服务","android.permission.USE_SIP"));
		temLst.add(new permissionInfo(R.drawable.ic_launcher,"唤醒锁定","允许程序在手机屏幕关闭后后台进程仍然运行","android.permission.WAKE_LOCK"));
    	

		mPermissionList = new ArrayList<ArrayList<permissionInfo>>();
    	parentLst = new ArrayList<String>();
    	ArrayList<permissionInfo> NormalLst = new ArrayList<permissionInfo>();
    	parentLst.add("普通权限");
    	ArrayList<permissionInfo> DangerousLst = new ArrayList<permissionInfo>();
    	parentLst.add("有危险性的权限");
    	ArrayList<permissionInfo> SystemLst = new ArrayList<permissionInfo>();
    	parentLst.add("系统级别的权限");
    	ArrayList<permissionInfo> HighSystemLst = new ArrayList<permissionInfo>();
    	parentLst.add("高级系统级别权限");
    	ArrayList<permissionInfo> UnknownLst = new ArrayList<permissionInfo>();
    	parentLst.add("未知权限");
    	mPermissionList.add(NormalLst);
    	mPermissionList.add(DangerousLst);
    	mPermissionList.add(SystemLst);
    	mPermissionList.add(HighSystemLst);
    	mPermissionList.add(UnknownLst);
    	
    	for(int i = 0; i < temLst.size(); i++)
    	{
    		if(temLst.get(i).showName.equalsIgnoreCase("状态栏控制"))
    		{
    			PermissionInfo tem = null;;
				try {
					tem = mPackageManager.getPermissionInfo(temLst.get(i).permissionName, 0);
					tem.toString();
				} catch (NameNotFoundException e) {
					e.printStackTrace();
				}
    					
    		}
    		int protectionLevel = 0;
			try {
				protectionLevel = mPackageManager.getPermissionInfo(temLst.get(i).permissionName, 0).protectionLevel;
			} catch (NameNotFoundException e) {
				e.printStackTrace();
				UnknownLst.add(temLst.get(i));
				temLst.get(i).nDrawableID = R.drawable.normal_permission;
				continue;
			}
    		switch (protectionLevel) {
			case PermissionInfo.PROTECTION_NORMAL:
				NormalLst.add(temLst.get(i));
				temLst.get(i).nDrawableID = R.drawable.normal_permission;
				break;
			case PermissionInfo.PROTECTION_DANGEROUS:
				DangerousLst.add(temLst.get(i));
				temLst.get(i).nDrawableID = R.drawable.dangerous_permission;
				break;
			case PermissionInfo.PROTECTION_SIGNATURE:
				temLst.get(i).nDrawableID = R.drawable.advance_permission;
				SystemLst.add(temLst.get(i));
				break;
			case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM:
				temLst.get(i).nDrawableID = R.drawable.deep_advance_permission;
				HighSystemLst.add(temLst.get(i));
				break;
			default:
				break;
			}
    	}
    }
    
	private class LoadFinishReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(final Context ctx, Intent intent) {
           // setProgressBarIndeterminateVisibility(false);
            adapter = new MainPermissionListAdapters(PermissionLevelActivity.this,mPermissionList,parentLst);
            getListView().setAdapter(adapter);//setAdapter(adapter);
        }
    }
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		this.unregisterReceiver(loadFinish);
	}



	@Override
	public void PackageAdded(String packageName) 
	{
		refresh();
	}



	@Override
	public void PackageRemoved(String packageName) 
	{
		refresh();
	}
}
